package hc.bre.cmn

@groovy.transform.CompileStatic
@groovy.transform.ToString(includeNames=true,includePackage=false)
class ListOption implements IListOption,ILoad, Serializable {
	int id
	String code
	String name

	ListOption load(Map map) {
		Integer val ;
		val = map['id'] as Integer;
		if(val == null) {
			throw new Exception("invalid number of Id when loading [${map}] of ${this.getClass().getName()}");
		}

		this.id = val;
		this.code = map ['code'];
		this.name = map['name'];

		return this;
	}

	public codeAsGetSetter() {
		if(!this.code) {
			throw new Exception('wrong empty code of .'+ this)
		}

		return code[0].toUpperCase() + code.substring(1);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ListOption other = (ListOption) obj;
		if (id != other.id)
			return false;
		return true;
	}
}
